<?php

include_once ("common.php");

//技术支持：<a  href='http://www.dreammm.net'>唤梦科技QQ 75039960,Mobile 18665802636 </a>

/*
你在公众号查询一个没有查询过的
imei, sn
近期查询过的系统会缓存数小时
*/


//include_once   ("get_access_token.php");





function phoneImeiInfo_2($fromUsername,$toUsername,$keyword,$isImei){
	$textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                <FuncFlag>0</FuncFlag>
                </xml>";
                                     //构造XML数据格式
	$msgType = "text";                         //定义响应消息类型text

     //http://data.3023.com/apple/imei/
    //$url = "https://api.3023.com/apple/apple?imiei=$keyword"

    //  $url = "https://api.3023.com/apple/imei?imei=$keyword";
     //http://data.3023.com/apple/coverage/senior/
      //http://data.3023.com/apple/coverage/
      //if(!$isImei)
       //$url = "https://api.3023.com/apple/coverage?app=senior&sn=$keyword";
       //else
       $url = "https://api.3023.com/apple/coverage?sn=$keyword";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("key:c07440ba148e7822b4a7a8c819d2d129"));

curl_setopt($ch,CURLOPT_TIMEOUT,60);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,15);
$response = curl_exec($ch);
curl_close($ch);
$jsonStr = json_decode($response,true);

     $json = json_decode($response,true);
    //print_r($jsonStr);  //这个可以看下错误的输出样本

    if(!$json["applecare"])  $json["applecare"] = "否";
    else  $json["applecare"] = "是";

    if(!$json["refurbished"])  $json["refurbished"] = "否";
    else  $json["refurbished"] = "是";

   if(!$json["renovate"])  $json["renovate"] = "否";
    else  $json["renovate"] = "是";



    if(!$json["activated"])  $json["activated"] = " 未激活";
     else  $json["activated"] = "已激活";

    if($json["support"]=="expired")  $json["support"] = "过期";

     if($json["coverage"]=="expired")  $json["coverage"] = "过期";

  if($json["message"])
          $contentStr = $json["message"];
   else
   {
    $contentStr="输入数据:$keyword\n";			//结果字符串
    $contentStr =  $contentStr ."查询结果:\n";
    $contentStr =  $contentStr . "序列号:" .$json["sn"]."\n" ;
    if($isImei)
    $contentStr =  $contentStr . "IMEI:" .$json["imei"]."\n" ; //只有imei才有这个结果的

    $contentStr =  $contentStr . "型号:" .$json["model"]."\n" ;
    $contentStr =  $contentStr . "容量:" .$json["capacity"]."\n" ;
    $contentStr =  $contentStr . "颜色:" .$json["color"]."\n" ;
    $contentStr =  $contentStr . "版本:" .$json["number"]."\n" ;
    $contentStr =  $contentStr . "类型:" .$json["identifier"]."\n" ;
    $contentStr =  $contentStr . "模型:" .$json["model"]."\n" ;
    $contentStr =  $contentStr . "网络:" .$json["network"]."\n" ;

    $contentStr =  $contentStr . "激活状态:" .$json["activated"]."\n" ;
    $contentStr =  $contentStr . "首次激活日期:" .$json["purchase"][date]."\n" ;
    $contentStr =  $contentStr . "保修结束日期:" .$json["coverage"]."\n" ;
    $contentStr =  $contentStr . "保修剩余:" .$json["daysleft"]."\n" ;
    $contentStr =  $contentStr . "技术支持有效期:" .$json["support"]."\n" ;
     $contentStr =  $contentStr . "是否延保 :" .$json["applecare"]."\n" ;
      $contentStr =  $contentStr . "是否官换机 :" .$json["refurbished"]."\n" ;
    //$contentStr =  $contentStr . "产品类型:" .$json["product"]."\n" ; ////这个是有这个数据的，和 identifier的数据差不多的，所以屏蔽
    $contentStr =  $contentStr . "出厂日期:" .$json["production"]["end"]."\n" ;
    $contentStr =  $contentStr . "产地:" .$json["production"]["origin"]."\n" ;
     $contentStr =  $contentStr . "是否翻新机:"   .  $json["renovate"]."\n" ;
    //$contentStr =  $contentStr . "翻新机概率:"   .  $json["renovate"]["probability"]."\n" ;
    //$contentStr =  $contentStr . "鉴定结果:" . $json["renovate"]["result"]."\n" ;
    //$contentStr =  $contentStr . "设备图片:" .$json["img"]."\n" ;
    $contentStr =  $contentStr ."此查询结果来自微信公众号：梦想青年科技,若查询有误请参考苹果官网www.apple.com.cn ";

    }

//$contentStr = $response;
	$responseStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $msgType, $contentStr);
    	//把格式化的字符串写入变量
    	echo   $responseStr;


}



function phoneImeiInfo($postObj,$keyword,$isImei)
{
	$textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                <FuncFlag>0</FuncFlag>
                </xml>";
                                     //构造XML数据格式
	$msgType = "text";                         //定义响应消息类型text



  //http://data.3023.com/apple/coverage/senior/
      //http://data.3023.com/apple/coverage/
      //if(!$isImei)
       //$url = "https://api.3023.com/apple/coverage?app=senior&sn=$keyword";
       //else

       $url = "https://api.3023.com/apple/coverage?sn=$keyword";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("key:c07440ba148e7822b4a7a8c819d2d129"));

curl_setopt($ch,CURLOPT_TIMEOUT,60);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,15);
$response = curl_exec($ch);
curl_close($ch);
$jsonStr = json_decode($response,true);

     $json = json_decode($response,true);

    if(!$json["applecare"])  $json["applecare"] = "否";
    else  $json["applecare"] = "是";

    if(!$json["refurbished"])  $json["refurbished"] = "否";
    else  $json["refurbished"] = "是";

   if(!$json["renovate"])  $json["renovate"] = "否";
    else  $json["renovate"] = "是";



    if(!$json["activated"])  $json["activated"] = " 未激活";
     else  $json["activated"] = "已激活";

    if($json["support"]=="expired")  $json["support"] = "过期";

     if($json["coverage"]=="expired")  $json["coverage"] = "过期";

  if($json["message"])
          $contentStr = $json["message"];
   else
   {
    $contentStr="输入数据:$keyword\n";			//结果字符串
    $contentStr =  $contentStr ."查询结果:\n";
    $contentStr =  $contentStr . "序列号:" .$json["sn"]."\n" ;
    if($isImei)
    $contentStr =  $contentStr . "IMEI:" .$json["imei"]."\n" ; //只有imei才有这个结果的

    $contentStr =  $contentStr . "型号:" .$json["model"]."\n" ;
    $contentStr =  $contentStr . "容量:" .$json["capacity"]."\n" ;
    $contentStr =  $contentStr . "颜色:" .$json["color"]."\n" ;
    $contentStr =  $contentStr . "版本:" .$json["number"]."\n" ;
    $contentStr =  $contentStr . "类型:" .$json["identifier"]."\n" ;
    $contentStr =  $contentStr . "模型:" .$json["model"]."\n" ;
    $contentStr =  $contentStr . "网络:" .$json["network"]."\n" ;

    $contentStr =  $contentStr . "激活状态:" .$json["activated"]."\n" ;
    $contentStr =  $contentStr . "首次激活日期:" .$json["purchase"][date]."\n" ;
    $contentStr =  $contentStr . "保修结束日期:" .$json["coverage"]."\n" ;
    $contentStr =  $contentStr . "保修剩余:" .$json["daysleft"]."\n" ;
    $contentStr =  $contentStr . "技术支持有效期:" .$json["support"]."\n" ;
     $contentStr =  $contentStr . "是否延保 :" .$json["applecare"]."\n" ;
      $contentStr =  $contentStr . "是否官换机 :" .$json["refurbished"]."\n" ;
    //$contentStr =  $contentStr . "产品类型:" .$json["product"]."\n" ; ////这个是有这个数据的，和 identifier的数据差不多的，所以屏蔽
    $contentStr =  $contentStr . "出厂日期:" .$json["production"]["end"]."\n" ;
    $contentStr =  $contentStr . "产地:" .$json["production"]["origin"]."\n" ;
     $contentStr =  $contentStr . "是否翻新机:"   .  $json["renovate"];//."\n" ;
    //$contentStr =  $contentStr . "翻新机概率:"   .  $json["renovate"]["probability"]."\n" ;
    //$contentStr =  $contentStr . "鉴定结果:" . $json["renovate"]["result"]."\n" ;
    //$contentStr =  $contentStr . "设备图片:" .$json["img"]."\n" ;
    //$contentStr =  $contentStr ."此查询结果来自微信公众号：梦想青年科技,若查询有误请参考苹果官网www.apple.com.cn ";

    }

    send_mess($postObj, $contentStr);

    	//$responseStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $msgType, $contentStr);

    	//$responseStr = sprintf($textTpl,$postObj->FromUserName, $postObj->ToUserName, time(), $msgType, $contentStr);
    	//echo   $responseStr;

     return true;

}



?>